Using Movie Controller Components
This section supplies examples of how to use the standard movie controller to play movies. It also provides sample code for customizing movie controller components.Playing Movies
The following sample code demonstrates how to use the standard movie controller component to play a movie. TheGetMovie
function prompts the user to select a movie file and then get a movie out of it. It then opens the movie and allows the user to play it.Listing 2-1 Playing a movie with a movie controller component
MovieController gController; WindowPtr gWindow; Rect windowRect; Movie gMovie; Boolean gDone; OSErr gErr; ComponentResult gCErr; Boolean gResult; EventRecord gTheEvent; WindowPtr whichWindow; short part; pascal Movie GetMovie(void); pascal Movie GetMovie(void) { OSErr err; SFTypeList typeList; StandardFileReply reply; Movie aMovie; short movieResFile; short movieResID; Str255 movieName; Boolean wasChanged; aMovie = nil; typeList[0] = MovieFileType; StandardGetFilePreview ( (FileFilterProcPtr)nil, 1, typeList, &reply); if (reply.sfGood) { err = OpenMovieFile (&reply.sfFile, &movieResFile, fsRdPerm); if (err == noErr) { movieResID = 0; err = NewMovieFromFile (&aMovie, movieResFile, &movieResID, movieName, newMovieActive, &wasChanged); err = CloseMovieFile (movieResFile); } } return aMovie; } void main(void); void main(void) { InitGraf(&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(nil); gErr = EnterMovies(); SetRect (&windowRect, 100, 100, 200, 200); gWindow = NewCWindow (nil, &windowRect, "\pMovie", false, noGrowDocProc, (WindowPtr)-1, true, 0); SetPort (gWindow); gMovie = GetMovie(); if (gMovie != nil) { SetRect(&windowRect, 0, 0, 100, 100); gController = NewMovieController (gMovie, &windowRect, mcTopLeftMovie); if (gController != nil) { gCErr = MCGetControllerBoundsRect (gController, &windowRect); SizeWindow (gWindow, windowRect.right, windowRect.bottom, true); ShowWindow (gWindow); gCErr = MCDoAction (gController, mcActionSetKeysEnabled, (Ptr)true); gDone = false; while (! gDone) { gResult = GetNextEvent (everyEvent, &gTheEvent); if (MCIsPlayerEvent (gController, &gTheEvent) == 0) { switch (gTheEvent.what) { case updateEvt: whichWindow = (WindowPtr)gTheEvent.message; BeginUpdate (whichWindow); EraseRect (&(*whichWindow).portRect); EndUpdate (whichWindow); break; case mouseDown: part = FindWindow (gTheEvent.where, &whichWindow); if (whichWindow == gWindow) { switch (part) { case inGoAway: gDone = TrackGoAway (whichWindow, gTheEvent.where); break; case inDrag: DragWindow (whichWindow, gTheEvent.where, &(qd.screenBits.bounds) ); break; } } } } } DisposeMovieController(gController); } DisposeMovie(gMovie); } DisposeWindow(gWindow); }Customizing Movie Controllers
Movie controller components allow you to create an action filter function in your application. The component calls your action filter function whenever an action occurs in the control. (An action is an integer constant used by the movie controller component.) You can then customize the behavior of the control or simply monitor user actions. You establish an action filter function by calling theMCSetActionFilterWithRefCon
function, which is described on page 2-47.The sample code in Listing 2-2 demonstrates the use of an action filter function. This filter function resizes the window whenever the user hides the controller. Therefore, this sample function handles the
mcActionControllerSizeChanged
action. Your application should include a similar action filter function so that you can determine when the user resizes the controller. This function supports only attached controllers.Listing 2-2 Using a movie controller filter function
pascal Boolean myMCActionFilter ( MovieController mc, short* Action, long* params); { RgnHandle controllerRgn; Rect controllerBox; WindowPtr movieWindow; switch (*Action) { case mcActionControllerSizeChanged: /* size of controller/movie has changed */ movieWindow = (WindowPtr)MCGetControllerPort(mc); controllerRgn = MCGetWindowRgn(mc, movieWindow); if (controllerRgn != nil) { controllerBox = (**controllerRgn).rgnBBox; DisposeRgn (controllerRgn); SizeWindow (movieWindow, controllerBox.right, controllerBox.bottom, true); } break; } return false; }
Subtopics
- Playing Movies
- Customizing Movie Controllers
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help